package com.doudou.oauth.handler;

import com.doudou.commons.utils.BrowserUtils;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


/**
 * @Description: 认证成功的逻辑处理
 * @author: 傻男人
 * @Date: 2019\10\29
 */
@Component
public class SuccessLoginHandler extends SimpleUrlAuthenticationSuccessHandler {

    @Autowired
    ObjectMapper objectMapper;

    /**
     *
     * Called when a user has been successfully authenticated.
     *
     * @param request        the request which caused the successful authentication
     * @param response       the response
     * @param authentication the <tt>Authentication</tt> object which was created during
     */
    @Override
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
        if(BrowserUtils.isBrowser(request)){
            System.out.println("--------------------------登录成功-----------------------");
            super.onAuthenticationSuccess(request,response,authentication);
        }else {
            super.onAuthenticationSuccess(request,response,authentication);
        }
    }
}
